package com.fbee.smartcommunities.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fbee.smartcommunities.entity.Role;
import com.fbee.smartcommunities.service.RoleService;
import com.fbee.smartcommunities.vo.ResultVO;
import io.minio.errors.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 调整AUTO_INCREMENT值 前端控制器
 * </p>
 *
 * @author 汪佳泉
 * @since 2024-08-16
 */
@RestController
@RequestMapping("/role")
public class RoleController {

    @Resource
    private RoleService roleService;

    @GetMapping("/arr")
    public ResultVO<List<Role>> getRoles(Integer id){
        return ResultVO.success(roleService.getRoles(id));
    }

    @GetMapping("list")
    public ResultVO<IPage<Role>> getPage(Integer pageNo, Integer pageSize){
        return ResultVO.success(roleService.page(new Page<Role>(pageNo,pageSize)));
    }


    @GetMapping("/find")
    public ResultVO<IPage<Role>> getTargetPage(Integer pageNo, Integer pageSize, String keyword){
        return ResultVO.success(roleService.getTargetPage(pageNo,pageSize,keyword));
    }

    @PostMapping("/add")
    public ResultVO<Boolean> add(String name, String description) {
        return ResultVO.success(roleService.save(new Role(name,description)),"添加成功");
    }

    @GetMapping("/getById")
    public ResultVO<Role> getById(Long id){
        return ResultVO.success(roleService.list(new QueryWrapper<Role>().eq("id",id)).get(0));
    }

    @GetMapping("/check")
    public ResultVO<Boolean> check(Long id, String value, String column){
        return ResultVO.success(roleService.check(id,value,column));
    }

    @PostMapping("/update")
    public ResultVO<Boolean> update(Long id, String name, String description){
        return ResultVO.success(roleService.update(id,name,description),null);
    }

}
